<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8" />
	<title>千郡医疗</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" th:href="@{/weixin/css/weui.min.css}" />
	<link rel="stylesheet" th:href="@{/weixin/css/style.css}" />
	<script type="text/javascript" th:src="@{/weixin/js/adaptive.js}"></script>
	<script type="text/javascript" th:src="@{/weixin/js/fastclick.min.js}"></script>
	<script type="text/javascript" th:src="@{/weixin/js/zepto.min.js}"></script>
	<script type="text/javascript" th:src="@{/weixin/js/weui.min.js}"></script>
	<style type="text/css">
	 body{font-size: initial !important;}
	</style>
</head>
<body>
	<section class="register">
		<form id="form">
		<input type="hidden" name="type" th:value="${type}" />
		<input th:if="${!#strings.isEmpty(from)}" type="hidden" name="recommendId" th:value="${from}" />
		<ul class="list">
			<li><input type="text" id="name" name="name" class="txt" placeholder="请输入您的名字" /></li>
			<li><input type="text" id="mobile" name="phoneNo" class="txt" placeholder="请输入您的手机号码" /></li>
			<li class="rel">
				<input type="text" id="code" name="verifyCode" class="txt" placeholder="输入验证码" />
				<a href="javascript:;" class="getCode">发送验证码</a>
				<span class="countDown" style="display:none"><i></i>秒后可重新发送</span>
			</li>
			<li><input type="password" name="password" id="pwd" class="txt" placeholder="请输入密码" /></li>
			<li><input type="password" id="pwd2" class="txt" placeholder="请输入确认密码" /></li>
		</ul>
		</form>
		<p class="subBox mt50"><a id="submit" href="javascript:;" class="comBtn">注册</a></p>
	</section>
	<script type="text/javascript">
		$(function(){
			FastClick.attach(document.body);
			$("#submit").click(submit);
			$('.getCode').click(getcode);
		});
		
		function countdown(sendObj,getCode,times) {
		    $(getCode).find('i').text(times);
		    currTimes = setInterval(function() {
		        times--;
		        $(getCode).find('i').text(times);
		        if(times == 0) {
		            $(getCode).hide().find('i').text(times);
		            $(sendObj).show();
		            clearInterval(currTimes);
		        }
		    }, 1000);
		}
		
		function getcode() {
			if(!(/^1[34578]\d{9}$/.test($("#mobile").val()))){ 
		        weui.alert("请输入正确的手机号码");  
		        return false; 
		    } 
			
			var l = weui.loading("正在提交")
			$.get("/qianjun/sms/code?mobile=" + $("#mobile").val(), function(data) {
                l.hide();
			    if (!data.success){
			        weui.alert(data.msg);
			        return;
				}
			    
			    var cunt=$(".getCode").next('.countDown');
		        $(".getCode").hide();
		        cunt.show();
		        countdown(".getCode",'.countDown',60);
			})
			return true;
		};
		
		function submit() {
			if (!validate())
				return;

			var l = weui.loading("正在提交")
			$.ajax({
				cache : true,
				type : "POST",
				url : "/qianjun/weixin/customer/registe",
				data : $('#form').serialize(),
				error : function(request) {
					l.hide();
					weui.alert("Connection error");
				},
				success : function(data) {
					l.hide();
					if (data.success){
	                    window.location.href =  "/qianjun/weixin/success?msg=" + data.msg;
						return;
					}
					weui.alert(data.msg);
				}
			});
		}
		
		function validate() {
			if($("#name").val() == ''){
				weui.alert("名字不能为空");
				return false;
			}
			
			if($("#mobole").val() == '' || $("#code").val() == ''){
				weui.alert("手机号和验证码不能为空");
				return false;
			}
			
			if($("#pwd").val() == ''){
				weui.alert("密码不能为空");
				return false;
			}
			
			if ($("#pwd").val() != $("#pwd2").val()) {
				weui.alert("两次密码不一致");
				return false;
			}

			return true;
		}
	</script>
</body>
</html>